package com.example.commonlib;

import android.text.TextUtils;

import com.hyk.commonLib.common.entity.INetObj;
import com.hyk.commonLib.common.utils.GsonUtils;

import org.jetbrains.annotations.NotNull;

public class NetBaseObj<T> implements INetObj<T> {

    protected static final String YES = "YES";
    protected static final String NO = "NO";

    public static final String UNKNOWN_SERVER_ID = "0000";

    public static final String STATUS_CODE_SUCCESS = "0";
    public static final String STATUS_CODE_AUTH_EXPIRED = "100001";
    public static final String STATUS_CODE_COMMON_ERROR = "999999";

    private String code;
    private String errMsg;
    private T data;


    @NotNull
    @Override
    public String toString() {
        return GsonUtils.getInstance().toJson(this);
    }

    @Override
    public T getData() {
        return data;
    }

    @Override
    public void setData(T t) {
        this.data = t;
    }

    @Override
    public String getStatusCode() {
        return code;
    }

    @Override
    public void setStatusCode(String s) {
        this.code = s;
    }

    @Override
    public void setStatusCodeAsError() {
        this.code = UNKNOWN_SERVER_ID + STATUS_CODE_COMMON_ERROR;
    }

    @Override
    public void setStatusCodeAsSuccess() {
        this.code = STATUS_CODE_SUCCESS;
    }

    @Override
    public String getMessage() {
        return errMsg;
    }

    @Override
    public void setMessage(String s) {
        this.errMsg = s;
    }

    @Override
    public boolean isSuccess() {
        return TextUtils.equals(code, STATUS_CODE_SUCCESS);
    }

    @Override
    public boolean isTokenExpired() {
        return false;
    }
}
